<template>
  <!-- 歌单展示组件 -->
  <div class="song_list_item" v-if="songList.length !== 0">
    <div
      class="item"
      v-for="(item, index) in songList"
      :key="index"
      @click="songListItemClick(item)"
    >
      <div class="pic_box">
        <img
          :src="item.picUrl ? item.picUrl : item.coverImgUrl"
          class="pic_url"
          :alt="item.name"
        />
        <div class="play_count_mark"></div>
        <div class="play_count">
          <div class="left">
            <span style="margin-right: 5px"></span>
            <span>{{ calPlayCount(item.playCount) }}</span>
          </div>
          <div class="right"></div>
        </div>
      </div>
      <div class="name">{{ item.name }}</div>
    </div>
  </div>
</template>

<script>
import { defineComponent } from "vue";
import bigNumberTransform from "@/utils/bigNumberTransform";
export default defineComponent({
  name: "SongListItem",
  props: {
    songList: {
      type: Array,
      default: () => {
        return [];
      },
      require: true,
    },
  },
  setup(props, context) {
    // 将播放量转化
    let calPlayCount = (playCount) => {
      return bigNumberTransform(playCount);
    };

    // 点击某个歌单回调
    let songListItemClick = (item) => {
      context.emit("songListItemClick", item);
    };

    return {
      calPlayCount,
      songListItemClick,
    };
  },
});
</script>
<style scoped>
.song_list_item {
  width: 100%;

  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.item {
  width: 25%;
  margin-bottom: 20px;
}

.pic_box {
  width: 178px;
  height: 178px;
  margin: 0 auto;
  position: relative;
  cursor: pointer;
}
.pic_url {
  width: 100%;
  height: 100%;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
}
.play_count_mark {
  width: 100%;
  height: 30px;
  background-color: #222;
  position: absolute;
  bottom: 0;
  opacity: 0.5;
}
.play_count {
  width: 100%;
  height: 30px;
  position: absolute;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  color: #e9e8e8;
}
.name {
  width: 178px;
  margin: 0 auto;
  margin-top: 5px;
  color: #222;
  font-size: 15px;
  cursor: pointer;
}
.name:hover {
  text-decoration: underline;
}
</style>
